var app = getApp();
import { showActionSheet } from '../../utils/camera.js';
Page({
    data:{
        tabBar:[{ "name": "留言板",'icon':'/images/liu1.png','url':'../home/home' },{ "name": "我的",'icon':'/images/mine1.png','url':'../mine/mine' }],
        moveIndex:1,
        myInfo:{}
    },
    clickTab:function(e){
        // console.log(e);
        var self=this
        var list=self.data.tabBar
        var index=e.currentTarget.id
        // console.log(list[2])
        self.setData({
            moveIndex:index ,
        })
        wx.redirectTo({
            url: list[index].url
        })  
  },
  camera: function (e) {
    var self = this
    showActionSheet({ name: 'headimg', isOne: 1, type: { "type": 'headimg' } }).then(data => {
      var user = data.user
      wx.setStorageSync('wechat_service_user', user)
      app.globalData.userInfo = user
      self.setData({
        user: user
      })
    })
  },
  onReady:function(){
      var value = wx.getStorageSync('userInfo')
      var self=this
    //   app.showToast()
      wx.request({
        url: 'https://www.hibigpc.com/getMyInfo',
        method:'post',
        data: {
            uuid:value.uuid
        },
        header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
        success: function(res) {
            console.log(res.data)
            var info=res.data.dataWrapper.tbMyInfo
            self.setData({
                myInfo:info
            })
        }
    })

  },
  checkMail:function(){
      var that=this
        wx.getLocation({
            type: 'wgs84',
            success: function(res) {
                // console.log(res)
                var latitude=res.latitude
                var longitude=res.longitude
                var brand=wx.getStorageSync('brand')
                var long2=brand.location.split(',')[0]
                var lat2=brand.location.split(',')[1]
                wx.request({
                    url: 'https://www.hibigpc.com/valideauthority',
                    method:'post',
                    data: {
                        long1:longitude,
                        lat1:latitude,
                        long2:long2,
                        lat2:lat2,
                    },
                    header: {
                        'content-type': 'application/x-www-form-urlencoded'
                    },
                    success: function(res) {
                        if(res.data.status=='-1'){
                            wx.showModal({
                                title: '提示',
                                content: res.data.msg,
                                showCancel:false
                            })
                        }else{
                            that.camera()
                        }
                        
                    }
                })
            }
        })  
    },
    onShareAppMessage: function () {
        var brandId=wx.getStorageInfoSync('brandId')
        return {
        title: '到此一玩小程序',
        path: '/pages/home/home?brandId='+brandId,
        success: function(res) {
            // 分享成功
        },
        fail: function(res) {
            // 分享失败
        }
        }
    }
})